package com.applet.mallappletbackstage.controller;


import com.applet.mallappletbackstage.entity.PersonnelInfo;
import com.applet.mallappletbackstage.entity.vo.UInfoVO;
import com.applet.mallappletbackstage.service.PersonnelInfoService;
import com.applet.mallappletbackstage.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author X
 * @since 2020-08-17
 */
@RestController
@RequestMapping("/mallappletbackstage/personnel-info")
public class PersonnelInfoController {

    @Autowired
    private PersonnelInfoService personnelInfoService;

    /***
     * 添加人员信息
     * @param openid
     * @param personnelInfo
     * @return
     */
    @PostMapping("/addInfo/{openid}")
    public R addInfo(@PathVariable(value = "openid")String openid,
                     @RequestBody PersonnelInfo personnelInfo) {
        int count = personnelInfoService.addInfo(openid,personnelInfo);
        if (count > 0) {
            return R.success("保存成功");
        }
        return R.fail("保存失败");
    }

    /***
     * 查询数据库是否有该用户数据
     * @param openid
     * @return
     */
    @GetMapping("/getInfo/{openid}")
    public R getInfo(@PathVariable(value = "openid")String openid) {
        PersonnelInfo personnelInfo = personnelInfoService.getInfo(openid);
        return R.success("查询成功",personnelInfo);
    }

    /***
     * 更新该用户数据
     * @param openid
     * @param personnelInfo
     * @return
     */
    @PostMapping("/upDataInfo/{openid}")
    public R upDataInfo(@PathVariable(value = "openid")String openid,
                     @RequestBody PersonnelInfo personnelInfo) {
        int count = personnelInfoService.upDataInfo(openid,personnelInfo);
        if (count > 0) {
            return R.success("保存成功");
        }
        return R.fail("保存失败");
    }
}

